package com.uvlab.sitespot.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;


/**
 * Spring注解方式实现任务调度, 2013, http://my.oschina.net/tanweijie/blog/190045
 * 
 * http://docs.spring.io/spring/docs/current/javadoc-api//org/springframework/
 * scheduling/annotation/Scheduled.html
 * 
 * http://spring.io/guides/gs/scheduling-tasks/
 * 
 * http://bbs.csdn.net/topics/390797317
 * 
 * @author allen
 *
 */

// @Configuration
// @EnableScheduling
// @ComponentScan(basePackages="com.myco.tasks")
public class JxAppTaskScheduler {

	// @Bean
	
	@Autowired 
	@Qualifier(value="svc")
	JxAppService svc;
	
	/*private JxStreamService streamservice;
	
	
	public JxAppTaskScheduler(){
	    this.streamservice=svc.newStreamService();
	}*/
	
	
	/*
	public JxAppTask task() {
		return new JxAppTask();
	}
	*/

	/**
	 * This method will run automatically every 10000 ms. 
	 * 
	 * modified by zhangwei on 2015.09.17
	 * - Comment the decorator to help debugging only. Should be uncommented in 
	 * the released version.
	 */
    // @Scheduled(fixedRate = 10000)
	public void evolve() {
		ftpFileDirMonitorAndImportTask();
		fdbRawDataFileChangeMonitorAndLoadTask();
		runTask();
	}
	
    
	public void runTask() {
		/*
		// task execution logic
		JxStreamService streamservice=svc.newStreamService();
	    streamservice.evolve(null, null);
		//System.out.println("JxAppTaskScheduler.runTask() was called.");
		*/
	}
	
	/**
	 * Task: monitor the ftp dir. If it found new file is uploaded, then try to
	 * import it into fdb.
	 */
	public void ftpFileDirMonitorAndImportTask()
	{
	//	System.out.println("JxAppTaskScheduler.ftpFileDirMonitorAndImportTask() was called.");
		
	}
	
	/**
	 * Task: Monitor the fdb. If it found the new raw data file, then it will 
	 * try to read the file, parse the fundamental data format and load them into
	 * stream service or dataset service. 
	 */
	public void fdbRawDataFileChangeMonitorAndLoadTask()
	{
		//System.out.println("JxAppTaskScheduler.fdbRawDataFileChangeMonitorAndLoadTask() was called.");
		
	}
	
}
